﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TFSTools.TFSLibrary;

namespace TFSTools.TestManagement.TestCaseReview
{
    /// <summary>
    /// Interaction logic for WorkItemTestView
    /// </summary>
    public partial class WorkItemTestView : Window
    {
        private TFSConnection tfsConnection;
        private TFSWorkItem workItem = null;

        public WorkItemTestView(TFSConnection connection)
        {
            this.InitializeComponent();

            this.tfsConnection = connection;
            this.txtWorkItemId.Text = "6307";
        }

        private void LookupButton_Click(object sender, RoutedEventArgs e)
        {
            this.workItem = this.tfsConnection.WorkItemStore.FindWorkItem(System.Convert.ToInt32(this.txtWorkItemId.Text));

            if (this.workItem != null)
            {
                this.lblIdAndTitle.Content = string.Format("{0}: {1}", this.workItem.Id, this.workItem.Title);

                this.DataContext = new WorkItemTestDataContext(this.workItem);
            }
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.workItem != null)
                {
                    this.workItem.Save();
                    this.LookupButton_Click(sender, e);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void ExitButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
